/*kZime*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define MAXN 100
using namespace std;
inline int read() {
	int k = 0, f = 1; char c = getchar();
	for(; !isdigit(c); c = getchar())if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
	return k * f;
}
/*-----------------------------------------------------------------------------*/
int n, m, en, head[MAXN];

struct edge{
	int fr, to, ne;
}e[MAXN * MAXN];

void add_edge(int a, int b) {
	e[++en].fr = a;
	e[en].to = b;
	e[en].ne = head[a];
	head[a] = en;
}

bool vis[MAXN];
int AC() {
#ifndef MYLAB
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#else
	freopen("in.txt", "r", stdin);
#endif
	
	n = read();
	m = read();
	
	for(int i = 1; i <= n; i++) {
		int x = read();
		int y = read();
		add_edge(x, y);
	}
	queue <int> q;
	q.push(1);
	vis[1] = true;
	while (!q.empty()) {
		int now = q.front();
		q.pop();
		for (int i = head[now]; i; i = e[i].ne) {
			printf("%d to %d\n", e[i].fr, e[i].to);
			if (!vis[e[i].to]) {
				q.push(e[i].to);
				vis[e[i].to] = 1;
			}
		}
	}
	return 0;
}
int HA = AC();
int main(){;}

